package com.hualan.zhsq.service.impl.car;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.car.Vehicle;
import com.hualan.zhsq.mapper.car.VehicleMapper;
import com.hualan.zhsq.service.car.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName VehicleServiceImpl
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月05日 下午9:41
 * @Version 1.0
 */
@Service("vehicleService")
public class VehicleServiceImpl implements VehicleService {
    @Autowired
    private VehicleMapper vehicleMapper;

    @Override
    public Map<String, Object> vehicleResident(Integer pageNum, Integer pageSize, Vehicle vehicle) {
        Page<Vehicle> page = new Page<>(pageNum, pageSize);
        Page<Vehicle> vehiclePage = vehicleMapper.selectAllPage(page,vehicle);
        Map<String, Object> map = new HashMap<>();

        long total=vehiclePage.getTotal();
        long size=vehiclePage.getSize();
        List<Vehicle> list=vehiclePage.getRecords();

        map.put("list", list);
        map.put("total", total);
        map.put("size", size);
        return map;
    }

    @Override
    public int add(Vehicle entity) {
        return vehicleMapper.insert(entity);
    }

    @Override
    public int edit(Vehicle entity) {
        return vehicleMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return vehicleMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return vehicleMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<Vehicle> find() {
        return vehicleMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Vehicle entity) {
        Page<Vehicle> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Vehicle> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del", 0);
        Page<Vehicle> vehiclePage = vehicleMapper.selectPage(page, queryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("list", vehiclePage.getRecords());
        map.put("total", vehiclePage.getTotal());
        map.put("size", vehiclePage.getSize());
        return map;
    }

    @Override
    public Vehicle findById(Integer id) {
        return vehicleMapper.selectById(id);
    }
}
